EMMA Coverage Report (generated Mon Sep 05 20:29:20 CEST 2016)
[all classes][net.mandaria.tippytipper.preferences]

COVERAGE SUMMARY FOR SOURCE FILE [NumberPickerPreference.java]

nameclass, %method, %block, %line, %
NumberPickerPreference.java100% (1/1)100% (6/6)94%  (223/236)92%  (54,2/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NumberPickerPreference100% (1/1)100% (6/6)94%  (223/236)92%  (54,2/59)
onSetInitialValue (boolean, Object): void 100% (1/1)60%  (18/30)52%  (4,2/8)
bindData (): void 100% (1/1)88%  (7/8)75%  (3/4)
NumberPickerPreference (Context, AttributeSet): void 100% (1/1)100% (48/48)100% (10/10)
onBindDialogView (View): void 100% (1/1)100% (6/6)100% (3/3)
onCreateDialogView (): View 100% (1/1)100% (120/120)100% (27/27)
onDialogClosed (boolean): void 100% (1/1)100% (24/24)100% (7/7)

1package net.mandaria.tippytipper.preferences;
2 
3import net.mandaria.tippytipper.R;
4import net.mandaria.tippytipper.widgets.*;
5import android.content.Context;
6import android.util.AttributeSet;
7import android.view.Gravity;
8import android.view.View;
9import android.preference.DialogPreference;
10import android.widget.TableLayout;
11import android.widget.TableRow;
12import android.widget.TextView;
13import android.content.res.*;
14 
15public class NumberPickerPreference extends DialogPreference
16{
17        private static final String androidns = "http://schemas.android.com/apk/res/android";
18 
19        private NumberPicker mPickInteger;
20        private TextView mSplashText;
21        private Context mContext;
22 
23        private String mDialogMessage, mSuffix;
24        private int mDefault, mMin, mMax, mValue = 0;
25 
26        public NumberPickerPreference(Context context, AttributeSet attrs)
27        {
28                super(context, attrs);
29                mContext = context;
30 
31                mDialogMessage = attrs.getAttributeValue(androidns, "dialogMessage");
32                mSuffix = attrs.getAttributeValue(androidns, "text");
33                mDefault = attrs.getAttributeIntValue(androidns, "defaultValue", 0);
34                mMax = attrs.getAttributeIntValue(androidns,"max", 100);
35            
36            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference);
37            mMin = a.getInt(R.styleable.SeekBarPreference_min, 0);
38        }
39 
40        @Override
41        protected View onCreateDialogView()
42        {
43                
44                TableLayout layout = new TableLayout(mContext);
45                layout.setPadding(6, 6, 6, 6);
46 
47                mSplashText = new TextView(mContext);
48                if (mDialogMessage != null)
49                        mSplashText.setText(mDialogMessage);
50 
51                TableRow row_header = new TableRow(mContext);
52                row_header.addView(mSplashText);
53 
54                mPickInteger = new NumberPicker(mContext);
55                mPickInteger.setRange(mMin, mMax);
56 
57                TextView suffix = new TextView(mContext);
58                suffix.setText(mSuffix);
59                suffix.setTextSize(32);
60 
61                TableRow row_one = new TableRow(mContext);
62                row_one.setGravity(Gravity.CENTER);
63                row_one.addView(mPickInteger);
64                row_one.addView(suffix);
65 
66                layout.addView(row_header);
67 
68                TableLayout table_main = new TableLayout(mContext);
69                table_main.addView(row_one);
70 
71                TableRow row_main = new TableRow(mContext);
72                row_main.setGravity(Gravity.CENTER_HORIZONTAL);
73                row_main.addView(table_main);
74 
75                layout.addView(row_main);
76 
77                if (shouldPersist())
78                        mValue = getPersistedInt(mDefault);
79 
80                bindData();
81 
82                return layout;
83        }
84 
85        private void bindData()
86        {
87                try
88                {
89                        mPickInteger.setCurrent(mValue);
90                }
91                catch (Exception ex)
92                {
93                        
94                }
95        }
96 
97        @Override
98        protected void onBindDialogView(View v)
99        {
100                super.onBindDialogView(v);
101                bindData();
102        }
103 
104        @Override
105        protected void onSetInitialValue(boolean restore, Object defaultValue)
106        {
107                super.onSetInitialValue(restore, defaultValue);
108                if (restore)
109                {
110                        try
111                        {
112                                mValue = shouldPersist() ? getPersistedInt(mDefault) : 0;
113                        }
114                        catch (Exception ex)
115                        {
116                                mValue = mDefault;
117                        }
118                }
119                else
120                        mValue = (Integer) defaultValue;
121        }
122 
123        @Override
124        protected void onDialogClosed(boolean positiveResult)
125        {
126                if (positiveResult == true)
127                {
128                        super.onDialogClosed(positiveResult);
129                        // HACK: "click" both picker inputs to validate inputs before closing the dialog
130                        // this is to fix a problem of closing the dialog not causing the onFocusChange of the picker
131                        // to be called
132                        mPickInteger.onClick(null);
133                        mValue = mPickInteger.getCurrent();
134                        if (shouldPersist())
135                                persistInt(mValue);
136                }
137        }
138}

[all classes][net.mandaria.tippytipper.preferences]
EMMA 2.0.5312 (C) Vladimir Roubtsov